﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenCRM.DomainServices.DomainEntities;
using OpenCRM.DataAccess.Entities;

namespace OpenCRM.DomainServices
{
    /// <summary>
    /// Give simple services of CRM app
    /// </summary>
    public class SimplesServices
    {
        /// <summary>
        /// Authenticates the  tennant.
        /// </summary>
        /// <param name="Login">The login.</param>
        /// <param name="Password">The password.</param>
        /// <returns>a security token to access other methods</returns>
        public string Authenticate(string Login, string Password)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Gets the clients list of the tennant authenticated by token.
        /// </summary>
        /// <param name="SecurityToken">The security token obtained via Authenticate.</param>
        public List<Client> GetClientsList(string userName)
        {
           
            SimpleModelDataContext contxt = new SimpleModelDataContext();

            var requete = from clients in contxt.cClients
                          where (clients.gTennant.Name == userName)
                          select clients;

            var resultatRequete = requete.AsQueryable();

            var mappingEFversEM = from t in resultatRequete
                                  select new Client { Nom = t.LastName, Prenom = t.FirstName };

            return mappingEFversEM.ToList<Client>();
            
        }

        public List<Client> GetClient(long idClient, string userName)
        {

            SimpleModelDataContext contxt = new SimpleModelDataContext();

            var requete = from clients in contxt.cClients
                          where ((clients.gTennant.Name == userName) && (clients.Id == idClient))
                          select clients;

            var resultatRequete = requete.AsQueryable();

            var mappingEFversEM = from t in resultatRequete
                                  select new Client { Nom = t.LastName, Prenom = t.FirstName };

            return mappingEFversEM.ToList<Client>();

        }
   
    }


    
}
